class_name InputManager
extends RefCounted


var enabled: bool:
	get:
		return __enabled
	set(value):
		__input_direction = Vector2.ZERO
		__is_just_attack = false
		__is_jump = false
		__enabled = value


var __enabled: bool = true
var __input_direction: Vector2 = Vector2.ZERO
var __is_just_attack: bool = false
var __is_jump: bool = false


func _process_input():
	if not __enabled:
		return
	movement_input()
	attack_input()
	jump_input()



func is_movement_input() -> bool:
	return __input_direction != Vector2.ZERO

func is_just_attack_input() -> bool:
	return __is_just_attack

func is_jump_input() -> bool:
	return __is_jump



func movement_input() -> Vector2:
	if __enabled:
		__input_direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	else:
		__input_direction = Vector2.ZERO
	return __input_direction


func attack_input() -> bool:
	if __enabled:
		__is_just_attack = Input.is_action_just_pressed("attack")
	else:
		__is_just_attack = false
	return __is_just_attack


func jump_input() -> bool:
	if __enabled:
		__is_jump = Input.is_action_just_pressed("jump")
	else:
		__is_jump = false
	return __is_jump


## 判断上下方向按键输入，按下上键返回-1，按下下键返回1，未按返回0
func up_down_input() -> int:
	if not __enabled:
		return 0
	if Input.is_action_just_pressed("ui_up"):
		return -1
	elif Input.is_action_just_pressed("ui_down"):
		return 1
	return 0


## 判断左右方向按键输入，按下左键返回-1，按下右键返回1，未按返回0
func left_right_input() -> int:
	if not __enabled:
		return 0
	if Input.is_action_just_pressed("ui_left"):
		return -1
	elif Input.is_action_just_pressed("ui_right"):
		return 1
	return 0


func accept_input() -> bool:
	if not __enabled:
		return false
	return Input.is_action_just_pressed("ui_accept")


func menu_input() -> bool:
	if not __enabled:
		return false
	return Input.is_action_just_pressed("ui_cancel")
